package org.business.accounting.service;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.business.accounting.beans.UserBean;
import org.business.accounting.beans.enums.Country;
import org.business.accounting.interfaces.User;

public class UserDAOImpl implements UserDAO {

	private Map<String, User> userMap;

	public UserDAOImpl() {
		userMap = new HashMap<String, User>();
		initializeAdmins();
	}
	
	private void initializeAdmins() {
		User user = new UserBean();
		user.setAdmin(true);
		user.setCountry(Country.Afganistan);
		user.setFirstName("Borko");
		user.setLastName("Djurovic");
		user.setPassword("111");
		user.setSpentMoney(0);
		user.setUserName("Borko");
		
		save(user);
	}

	public Collection<User> retrieve() {
		return userMap.values();
	}

	public User save(User user) {
		return userMap.put(user.getUserName(), user);
	}

	public User remove(String key) {
		return userMap.remove(key);
	}

	public void clear(boolean b) {
		if (b) {
			userMap.clear();
		}
	}

	public void addAll(Map<String, User> map) {
		userMap.putAll(map);
	}
	
	public User get(String key) {
		return userMap.get(key);
	}

	public Map<String, User> getUserMap() {
		return userMap;
	}

	public void setUserMap(Map<String, User> userMap) {
		this.userMap = userMap;
	}

}
